package com.mrd.gtimp.business.action;

import com.mrd.exception.QueryException;
import com.mrd.gtimp.business.entity.Declaration;
import com.mrd.gtimp.business.service.DeclarationBiz;
import com.mrd.gtimp.business.service.HongbaoBiz;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by dengdc on 2017/1/3.
 */
@Controller
@RequestMapping("/business/hb")
public class HongbaoAction {
	@Resource
	private HongbaoBiz		hongbaoBiz;
	@Resource
	private DeclarationBiz	declarationBiz;

	/**
	 * 补发红包
	 */
	@RequestMapping("/resend/auditOrder")
	@ResponseBody
	public String resendAuditOrderHongbao(String... orderBid) {
		for(String bid : orderBid) {
			try {
				String id = declarationBiz.findIdByBusinessId(bid);
				Declaration de = declarationBiz.findEntityById(id);
				hongbaoBiz.resendHongBao(de);
			} catch (QueryException e) {
				return e.getMessage();
			}
		}
		return "补发成功";
	}

	/**
	 * 补发红包, 激活补发任务，补发已经存有记录，状态为未发送的红包。
	 */
	@RequestMapping("/resend/invokeResendTask")
	@ResponseBody
	public String invokeResendTask() {
		try {
			hongbaoBiz.invokeResendTask();
		} catch (Exception e) {
			return "手动激活补发任务任务时出现异常:" + e.getMessage();
		}
		return "手动激活补发任务任务";
	}
}
